package com.hfkh.keyun.controller.frontend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hfkh.keyun.common.ApiResult;
import com.hfkh.keyun.entity.Resource;
import com.hfkh.keyun.exception.BusinessException;
import com.hfkh.keyun.service.ResourceService;
import com.hfkh.keyun.vo.ResourceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Author: jhh
 */

@RestController
@RequestMapping("/app/resource")
@Api(tags = "资源管理")
public class ResourceControllerApp {
    @Autowired
    public ResourceService resourceService;

    @GetMapping("/queryPage")
    @ApiOperation(value = "分页查询资源")
    public ApiResult queryPage(Integer page,
                               Integer limit,
                               Integer majorId) {
        Page<Resource> pageInfo = new Page<>(page, limit);
        Page<Resource> resourcePage = resourceService.selectResourcePage(pageInfo,majorId);
        return ApiResult.success(resourcePage);
    }

    @PostMapping("/addResource")
    @ApiOperation(value = "添加资源")
    public ApiResult addResource(ResourceVO resourceVO) throws IOException, BusinessException {
       return resourceService.AddSumUpdResource(resourceVO);
    }

    @PostMapping("/deleteResource")
    @ApiOperation(value = "删除资源")
    public ApiResult deleteResource(@RequestBody Integer id){
        resourceService.removeById(id);
        return ApiResult.ok("删除成功！", "头像上传成功！");
    }

}
